<?php
/**
 * Created by PhpStorm.
 * User: lingyun
 * Date: 2018/3/3
 * Time: 11:57
 * Desc: 网站设置模型
 */
namespace app\admin\model;
use think\Controller;
use think\Model;

class WebsiteModel extends Model{
    //设置对应的数据表明
    protected $table = 'ys_sys_level';
    protected $dateFormat = 'Y-m-d';
    protected $autoWriteTimestamp = true;       //默认自动写入时间戳是int类型

    /**
     * @Author  lingyun
     * @Desc    新增会员等级规则
     * @param $param
     * @return array
     */
    public function insert_level($param)
    {
        try{
            $result = $this->validate('WebsiteValidate.add')->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }

    /**
     * @Author  lingyun
     * @Desc    编辑会员等级规则
     * @param $param
     * @return array
     */
    public function edit_level($param)
    {
        try{
            $result =  $this->validate('WebsiteValidate.edit')->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
}